package com.yangtao.prototype.master.constant.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yangtao.framework.service.BaseService;
import com.yangtao.framework.util.StringHelper;
import com.yangtao.prototype.master.constant.service.ConstantModel;
import com.yangtao.prototype.master.constant.service.ConstantService;
import com.yangtao.prototype.master.dao.ConstantDAO;

@Service
public class ConstantServiceImpl extends BaseService implements ConstantService {
	@Autowired
	protected ConstantDAO cd;

	@Override
	public void getAllList(ConstantModel model) {
		model.setConstantList(cd.getAllList(model.getUser().getCompanyId()));
	}

	@Override
	public void getList(ConstantModel model) {
		model.getPage().setItems(cd.findByExample(model.getDomain()));
	}

	@Override
	public void save(ConstantModel model) {
		cd.saveOrUpdate(model.getDomain());
		model.addInfo("保存成功");
	}

	@Override
	public void load(ConstantModel model) {
		if (StringHelper.isNotEmpty(model.getDomain().getId())) {
			model.setDomain(cd.loadForReview(model.getDomain().getId()));
		}
	}

	@Override
	public void findConst(ConstantModel model) {
		String code = model.getCode();
		model.getPage().setItems(cd.findByCode(code));
	}

}
